package psn.zjk.common.algorithm.maxNum;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @USER white
 * 多数拼接，使结果最大
 * @DATETIME 2021/1/9 11:21
 */
public class Solution2 {

    public String solve(int[] nums) {
        if (nums == null || nums.length == 0) {
            return "";
        }
        if (Arrays.stream(nums).sum() == 0) {
            return "0";
        }
        List<Integer> sortedNums = Arrays.stream(nums).boxed().collect(Collectors.toList());
        sortedNums.sort((o1, o2) -> {
            if (Long.parseLong(String.valueOf(o1)+String.valueOf(o2))< Long.parseLong(String.valueOf(o2)+String.valueOf(o1))){
                return 1;
            }
           return -1;
        });
        StringBuilder stringBuilder = new StringBuilder();
        sortedNums.forEach(integer -> stringBuilder.append(integer));
        return stringBuilder.toString();
    }


    public static void main(String[] args) {
        int[] z = {10,1};
        String solve = new Solution2().solve(z);
        System.out.println(solve);
    }
}
